package com.iseastar.guojiang.print.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.iseastar.guojiang.model.PrintParcelBean;
import com.iseastar.guojiang.performance.PerformanceDetailActivity;
import com.shouhuobao.station.R;
import com.shouhuobao.take.utils.StringUtils;

import java.util.ArrayList;

import droid.frame.activity.base.BaseAdapterWithImage;

/**
 * Created by joker on 2017/7/25.
 */

public class PrintAdapter extends BaseAdapterWithImage<PrintParcelBean> {

    public PrintAdapter(ArrayList<PrintParcelBean> items, Activity context, ViewGroup listView) {
        super(items, context, listView);
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if (hasEmptyView()) {
            return super.getView(position, convertView, parent);
        }
        ViewHolder holder;
        if (convertView == null || convertView.getTag() == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_orderprint, parent, false);
            holder.goodsImageIV = (ImageView) convertView.findViewById(R.id.goodsImage_IV);
            holder.bagcodeTV = (TextView) convertView.findViewById(R.id.bagcode_TV);
            holder.senderPhoneTV = (TextView) convertView.findViewById(R.id.senderphone_TV);
            holder.senderTimeTV = (TextView) convertView.findViewById(R.id.sendertime_TV);
            holder.expressInfoTV = (TextView) convertView.findViewById(R.id.expressinfo_TV);
            holder.parcelStatusTV = (TextView) convertView.findViewById(R.id.parcelstatus_TV);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final PrintParcelBean item = items.get(position);
        showImage(item.getParcelImgUrl(), holder.goodsImageIV, null);
        holder.bagcodeTV.setText("投递编号: " + item.getBagCode());
        holder.senderPhoneTV.setText("下单人手机号: " + item.getSenderPhone());
        holder.expressInfoTV.setText(item.getExpressCompanyName() + ": " + item.getExpressNumber());
        holder.senderTimeTV.setText("下单时间: " + item.getCreateTime());
        if (context instanceof PerformanceDetailActivity) {
            if (StringUtils.isEmpty(item.getParcelStatusStr())) {
                holder.parcelStatusTV.setVisibility(View.GONE);
            } else {
                holder.parcelStatusTV.setVisibility(View.VISIBLE);
                holder.parcelStatusTV.setText(item.getParcelStatusStr());
            }
        } else {
            holder.parcelStatusTV.setVisibility(View.GONE);
        }
        return convertView;
    }

    private class ViewHolder {
        TextView bagcodeTV, senderPhoneTV, expressInfoTV, senderTimeTV;
        TextView parcelStatusTV;
        ImageView goodsImageIV;
    }
}
